package com.example.testdemo.scrollDelete;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.example.testdemo.R;

/**
 * Created by MrYan on 2018/8/24.
 * 侧滑删除demo
 */

public class ScrollDeleteActivity extends Activity {

    private RecyclerView deleteRv;
    private int position;
    private DeleteAdapter adapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scroll_delete);
        deleteRv = findViewById(R.id.deleteRv);
        deleteRv.setLayoutManager(new LinearLayoutManager(this));
        adapter = new DeleteAdapter();
        deleteRv.setAdapter(adapter);

        deleteRv.addOnItemTouchListener(new SwipeItemLayout.OnSwipeItemTouchListener(this));
        for (int i = 0; i < 5; i++) {
            addData();
        }
    }

    public void addItem(View view) {
        addData();
    }

    private void addData() {
        adapter.addData("第" + position + "条数据");
        position++;
    }
}
